package itfuge.testcallback;

import java.util.Timer;
import java.util.TimerTask;

public class Server {
    private DownLoadStatusCallback callback;
    private String mDownloadUrl = null;
    private Timer mTimer = null;
    private int mProgress = 0;
    public Server(DownLoadStatusCallback callback,String url){
        this.callback = callback;
        this.mDownloadUrl = url;
        mProgress = 0;
    }

    public void Run() {
        callback.showDownloadURL(mDownloadUrl);
        callback.startDownload();

        mTimer = new Timer();
        mTimer.schedule(new TimerTask() {
            @Override
            public void run() {
                callback.showDownloadProgress(mProgress);
                if (mProgress == 100) {
                    callback.stopDownload();
                    mTimer.cancel();
                }
                mProgress+=10;
            }
        },0,1000);
    }
}
